//
//  SN_Identify_ViewController.m
//  Shiyun_Newspaper
//
//  Created by zz on 17/6/27.
//  Copyright © 2017年 ShiYun. All rights reserved.
//

#import "SN_Identify_ViewController.h"
#import "SN_ChangePwd_Controller.h"

@interface SN_Identify_ViewController () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) UITableViewCell *cell1;

@property (nonatomic, strong) UITextField *field1;

@end

@implementation SN_Identify_ViewController

#pragma mark -Getter
- (UITableView *)tableView {
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight, VIEW_WIDTH, VIEW_HEIGHT - SafeAreaTopHeight) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.scrollEnabled = false;
        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT)];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
        [footerView addGestureRecognizer:tap];

        footerView.backgroundColor = [UIColor colorWithHexString:@"#f4f5f7"];
        _tableView.tableFooterView = footerView;
        _tableView.rowHeight = 44;
        
    }
    
    return _tableView;
}

- (UITableViewCell *)cell1 {
    
    if (!_cell1) {
        
        _cell1 = [[UITableViewCell alloc] init];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 14, 100, 16)];
        label.text = @"登录密码";
        label.textColor = [UIColor colorWithHexString:@"#3b3b3b"];
        label.font = [UIFont systemFontOfSize:16];
        [_cell1 addSubview:label];
        
        _field1 = [[UITextField alloc] initWithFrame:CGRectMake(92, 0, 230, 44)];
        _field1.placeholder = @"请输入登录密码";
        _field1.secureTextEntry = YES;
        _field1.borderStyle = UITextBorderStyleNone;
        _field1.textColor = [UIColor colorWithHexString:@"#3b3b3b"];
        [_cell1 addSubview:_field1];
        
        _cell1.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    return _cell1;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navBar.navigationItem.title = @"身份验证";
    
    UIBarButtonItem *nextStepBtn = [[UIBarButtonItem alloc] initWithTitle:@"下一步 " style:UIBarButtonItemStyleDone target:self action:@selector(nextSetpAction)];
    self.navBar.navigationItem.rightBarButtonItem = nextStepBtn;
    [nextStepBtn setTitleTextAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];
    [self.view addSubview:self.tableView];

}

#pragma mark -UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        
        return self.cell1;
        
    }else{
        
        return nil;
    }
}


#pragma mark -Action
- (void)nextSetpAction {
    
    if (_field1.text.length == 0) {
        
        [Utils alertViewWithMessage:@"请输入登录密码"];
        return;
    }
    
    if (![[SYAccountTool ShareAccount].account.loginpass isEqualToString:[Utils MD5EncryptWith:_field1.text]]) {
        
        [Utils alertViewWithMessage:@"密码输入错误,请重新输入"];
        return;
    }
    
    SN_ChangePwd_Controller *vc = [[SN_ChangePwd_Controller alloc] init];
    vc.type = @"2";
    vc.navTitle = @"修改绑定手机";
    [self.navigationController pushViewController:vc animated:YES];
    
}

- (void)tapAction {
    
    [self.view endEditing:YES];
}


@end
